import path from "path"
import { changeColor, createTonums, run, step, version } from "./utils"

let startIndex: string = '0'
let inPut: string = path.resolve('data')
let cols: any[] = []
let outputName: string = 'outPut'
let findName: string = ''
let format: string = 'yyyymmddhhmmss'

export function main(params: string | undefined): void {
    if (params) {
        inPut = path.resolve(params)
    }

    console.log(`
    ${changeColor(`❗※  Ver.${version}  只支持第1个Sheet页的合并 ※ ❗`, 107)}

    ${changeColor('主要功能:', 108)}
    ${changeColor('1、处理Excel文件数据', 108)}
    ${changeColor('2、合并多个Excel变成一个Excel', 108)}
    ${changeColor('3、处理列数据，目前仅支持日期格式的格式化，将2023-6-14 9:00:10、2023/6/14 9:00:10 格式化为 20230614090010', 108)}
    ${changeColor('4、处理列数据，1.0.1版本开始支持自定义处理列数据，可以自行到custom/custom.ts中自定义返回值, 详情阅读readme.md', 108)}`)

    console.log(`
    ${changeColor(`-> ${inPut}`, 102)}`)
    step(0).then(v => {
        findName = v || findName
        step(1).then(v => {
            outputName = v || outputName
            step(2).then(v => {
                cols = createTonums(v.split(','))
                step(3).then(v => {
                    format = v
                    run(startIndex, inPut, outputName, cols, findName, format, () => {
                        process.exit()
                    })
                })
            }, () => {
                main(undefined)
            })
        }, () => {
            main(undefined)
        })
    }, () => {
        main(undefined)
    })
}

